package tests;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 * Gui with hide/show "chatting" feature
 * Must be fixed!!
 * @author janmonterrubio
 *
 */
public class ChatFormat {

	private JTextField _chatField;
	private boolean _chatDisplay;
	private JPanel _chatPanel;
	
	public ChatFormat(){
	
		JFrame window = new JFrame("GUI");
		_chatPanel = new JPanel();
		_chatDisplay = true;
		_chatField = new JTextField(16);
		
		_chatPanel.add(_chatField);
		_chatPanel.setVisible(true);
		
		_chatField.setEditable(true);
		_chatField.addKeyListener(new KeyListener(){
					

				int en =  KeyEvent.VK_ENTER;
				int in;
				
						@Override
						public void keyPressed(KeyEvent arg0) {
							in = arg0.getKeyCode();
							if(in == en && (!_chatDisplay) && !_chatField.isEditable()){
								_chatField.setEditable(true);
								System.out.println("Enabling");
								_chatDisplay = true;
							}
							
							if(in == en && _chatDisplay){								
									System.out.println(_chatField.getText());
									_chatDisplay = false;
									_chatField.setText("");
									_chatField.setEditable(false);
								System.out.println("Disabling");
						}
						}

						@Override
						public void keyReleased(KeyEvent arg0) {
							// TODO Auto-generated method stub
							
						}

						@Override
						public void keyTyped(KeyEvent arg0) {
							// TODO Auto-generated method stub
							
						}
		}
						
				);
		
		window.add(_chatPanel, BorderLayout.SOUTH);
		
		window.setSize(500,500);
		window.validate();
		window.setVisible(true);
		
		
	}
	
	
	public static void main(String[] args){
		new ChatFormat();
		
	}
}
